package com.easy.controller;


import com.easy.bean.Bill;
import com.easy.service.BillService;
import com.easy.util.Page;
import com.easy.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@CrossOrigin//允许跨域访问
@RequestMapping("bill")
public class BillController {
    @Autowired
    BillService billService;

    @PostMapping
    public Result add(@RequestBody Bill bill) {
        Object obj=billService.add(bill);
        return Result.success(obj);
    }
    @PutMapping
    public Result edit(@RequestBody Bill bill) {
        Object obj=billService.edit(bill);
        return Result.success("编辑成功老弟",obj);
    }



    @DeleteMapping("{id}")
    public Result del(@PathVariable(name = "id") Integer id) { // 关键修复：显式指定name
        Object obj = billService.del(id);
        return Result.success("删除成功老弟",obj);
    }

    @GetMapping("{id}")
    public Result one(@PathVariable("id") Integer id) {
        Object obj=billService.one(id);
        return Result.success(obj);
    }
    @GetMapping("all")
    public Result all(Bill bill) {  // 去掉 @RequestBody，Spring 会自动绑定请求参数
        Object obj = billService.all(bill);
        return Result.success(obj);
    }

    @GetMapping("page")
    public Result page(Page page, 
                       Bill bill) {
        //查询一共多少页，多少条数据
        //查询当前页要显示的数据
        //封装数据到page对象中
        //返回page对象
        billService.page(page, bill);
        return Result.success(page);
    }
}
